package com.xy.farm.activity.deal.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.xy.farm.R;
import com.xy.farm.activity.deal.GoodsDetailsActivity;
import com.xy.farm.activity.deal.ShelvesActivity;

public class DealGoodsAdapter extends RecyclerView.Adapter<DealGoodsAdapter.ViewHolder>
{
    private int size = 4;
    public class ViewHolder extends RecyclerView.ViewHolder
    {
        private FrameLayout btn_shelves;
        private FrameLayout btn_details;
        public ViewHolder(View view)
        {
            super(view);
            switch (view.getTag().hashCode())
            {
                case 0:
                    btn_details = view.findViewById(R.id.btn_details);
                    break;
                case 1:
                    btn_shelves = view.findViewById(R.id.btn_shelves);
                    break;
            }
        }
    }
    @Override
    public int getItemCount()
    {
        return size + 1;
    }

    @Override
    public int getItemViewType(int position)
    {
        return position == size ? 1 : 0;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        if (viewType == 0)
        {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_deal_goods, parent, false);
            view.setTag(viewType);
            return new ViewHolder(view);
        }
        else
        {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_deal_putaway, parent, false);
            view.setTag(viewType);
            return new ViewHolder(view);
        }
    }
    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
        switch (holder.itemView.getTag().hashCode())
        {
            case 0:
                holder.btn_details.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View view)
                    {
                        Intent intent = new Intent(view.getContext(), GoodsDetailsActivity.class);
                        view.getContext().startActivity(intent);
                    }
                });
                break;
            case 1:
                holder.btn_shelves.setOnClickListener(new View.OnClickListener()
                {
                    @Override
                    public void onClick(View view)
                    {
                        Intent intent = new Intent(view.getContext(), ShelvesActivity.class);
                        view.getContext().startActivity(intent);
                    }
                });
                break;
        }
    }
}
